package com.dk.test.sms.client;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.json.rpc.client.HttpJsonRpcClientTransport;
import org.json.rpc.client.JsonRpcInvoker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dk.smsexpress.common.ServiceConstant;
import com.dk.smsexpress.common.base.IMobiSmsAutoSelectAccount;
import com.dk.smsexpress.common.base.IMobiSmsManualSelectAccount;
import com.dk.smsexpress.common.exception.SmsException;

public class InvokeServerMethod {

	final static Logger logger = LoggerFactory
			.getLogger(InvokeServerMethod.class);

	@SuppressWarnings("unchecked")
	public static void main(String args[]) throws MalformedURLException {
		// where the servlet is hosted
		//String url = "http://localhost:8888/smsexpress_server";
		//String url="http://localhost:8080/SmsServer/ActionHandler";
		logger.info("Start");
		String url="http://dksmsexpress.appspot.com/smsexpress_server";
		
		HttpJsonRpcClientTransport transport = new HttpJsonRpcClientTransport(
				new URL(url));

		JsonRpcInvoker invoker = new JsonRpcInvoker();
		IMobiSmsAutoSelectAccount mobiSmsAuto = invoker.get(transport,
				ServiceConstant.MOBIFONE_SMS_AUTO,
				IMobiSmsAutoSelectAccount.class);

		IMobiSmsManualSelectAccount mobiSmsManual = invoker.get(transport,
				ServiceConstant.MOBIFONE_SMS_MANUAL,
				IMobiSmsManualSelectAccount.class);

		try {
			mobiSmsAuto.SendMobiSMS("84933477833", "lle_03_Aug_2011_14_38_04");
		} catch (SmsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

//		try {
//			mobiSmsManual.SendMobiSMS("0933477833","FirstDoc123","84933477833", "Sample Text lle_03_Aug_2011_13_32_39");
//		} catch (SmsException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
		
		logger.info("Done");
	}
}
